{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c67af4b7",
   "metadata": {},
   "source": [
    "# 1. 语音录制\n",
    "\n",
    "* 1. 安装和下载模块：pip install 模块名称\n",
    "> 1. SpeechRecognition\n",
    "> 2. Pyaudio\n",
    "> 3. pydub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "35be7363",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "003718b8",
   "metadata": {},
   "source": [
    "# 2. 语音识别（百度的ASR）auto speech recognition\n",
    "\n",
    "* I/O: 音频文件--> 文本文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ce0a43d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdasr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b5694749",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "asr() missing 1 required positional argument: 'AUDIO_FILE'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m bd_asr_result \u001b[38;5;241m=\u001b[39m \u001b[43mbdasr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43masr\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m1.wav\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      2\u001b[0m bd_asr_result\n",
      "\u001b[1;31mTypeError\u001b[0m: asr() missing 1 required positional argument: 'AUDIO_FILE'"
     ]
    }
   ],
   "source": [
    "bd_asr_result = bdasr.asr('1.wav')\n",
    "bd_asr_result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a46ecc1e",
   "metadata": {},
   "source": [
    "# 3. 自然语言处理（NLP）\n",
    "* I/O: 文本--->文本（文本的生成：文本的理解，文本的处理，文本的生成）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "37b1bfcc",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa = {\n",
    "    \"网络与新媒体专业。\":\"网络与新媒体是一门普通高等学校本科专业，属新闻传播学类专业，学制四年，授予文学学士学位\",\n",
    "    \"你是谁？\":\"我是集美貌和智慧于一体的智能小网同学\",\n",
    "    '你好。':\"你也好，我是智能小新，很高兴为你服务\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ecaf2bb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
